package cn.edu.bupt.freewings.forum.server.rest;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import org.apache.log4j.Logger;
import cn.edu.bupt.freewings.forum.common.TopicType;
import cn.edu.bupt.freewings.forum.common.CommonType;
import cn.edu.bupt.freewings.forum.persistence.EntityManagerHelper;
import cn.edu.bupt.freewings.forum.persistence.Topic;
import cn.edu.bupt.freewings.forum.persistence.TopicDAO;
import cn.edu.bupt.freewings.forum.server.Utility.Converter;
import cn.edu.bupt.freewings.forum.server.Utility.MessageConstants;

/**
 * @author hubaiyu (hubaiyu@gmail.com)
 *
 */
@Path("/topic")
public class TopicResource {
	static Logger logger = Logger.getLogger(TopicResource.class);
	
	@PUT
	@Path("/new")
	@Consumes({"application/proto", "application/xml"})
	@Produces({"application/proto", "application/xml"})
	public CommonType.Empty put(TopicType.Topic topicType){
		Topic newTopic = Converter.TopicTypeToTopic(topicType);
		EntityManagerHelper.beginTransaction();
		new TopicDAO().save(newTopic);
		EntityManagerHelper.commit();
		return MessageConstants.EMPTY_MESSAGE;
	}
}
